package com.zqxq.lottery.service.user.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.lottery.config.YmlConfig;
import com.zqxq.lottery.entity.po.user.UserWindowMsgPO;
import com.zqxq.lottery.entity.vo.user.UserWindowMsgVO;
import com.zqxq.lottery.mapper.user.UserWindowMsgMapper;
import com.zqxq.lottery.service.user.IUserWindowMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class UserWindowMsgServiceImpl extends ServiceImpl<UserWindowMsgMapper,UserWindowMsgPO> implements IUserWindowMsgService {

    @Autowired
    private YmlConfig ymlConfig;
    public void saveUserMsg(Long userId,String title, String content, Integer type){
        UserWindowMsgPO po = new UserWindowMsgPO();
        po.setId(ymlConfig.getPkId());
        po.setUser_id(userId);
        po.setTitle(title);
        po.setContent(content);
        po.setType(type);
        po.setStatus(0);
        baseMapper.insert(po);
    }

    @Override
    public List<UserWindowMsgVO> queryList(String userId) {
        List<UserWindowMsgVO> list = baseMapper.queryList(userId);
        for(UserWindowMsgVO vo : list){
            UserWindowMsgPO po = baseMapper.selectById(vo.getId());
            po.setStatus(1);
            baseMapper.updateById(po);
        }
        return list;
    }

    @Override
    public void updateWindowMsg(String ids) {
        for(String id : ids.split(",")){
            UserWindowMsgPO po = baseMapper.selectById(id);
            po.setStatus(1);
            baseMapper.updateById(po);
        }
    }

}
